*---------------------------------------------TAX_CAP_EST_IVREG2_MLS.DO-----------------------------------------
*This script replicates much of the core analysis in tax_cap_est_ivreg2.do but does so using exclusively MLS sales data
*matched to tax roll data.
*The data differ in numerous respects including time period (2005-2010 only).  One key virtue of the MLS data, however, is the ability to 
*identify listing broker information, including experience (market share) and whether Reinhart was involved (#1 by market share).
*Ideally, I would test whether Reinhart buyers' agents help buyers avoid overcapitalization of temporary tax savings.  Instead, I only have
*listing broker identities.  If Reinhart agents are simply more scrupulous with respect to property taxes, buyers might conceivably benefit
*from Reinhart-listed transactions.  (Self selection into use of agents from particular brokerages is ignored).

*Sebastien Bradley 12/12/13


clear all
local path "C:/Users/sjb355/Documents/Research/PropertyTaxes"
capture cd "`path'/Ann_Arbor/MLS"
set matsize 600
set more off
capture log close

log using tax_cap_est_MLS_results_ivreg2.txt, text replace

/**/
*ADD NEIGHBORHOOD AND CENSUS TRACT IDENTIFIERS TO MERGED MLS - TAX ROLL DATA
*All parcels were geocoded in a previous step following exporting and formatting of addresses by format_AA_parcel_addresses.do
insheet using `path'/Ann_Arbor/AA_parcels_w_hoods_tracts.txt, clear tab names
foreach v of varlist neighborhood-census_tract {
	destring `v', replace
}
merge 1:m pid using "`path'/Ann_Arbor/AA_proptaxdata19972008/AA_GIS_data.dta", nogen
keep pid neighborhood-census_tract *_sch
foreach v of varlist *_sch {
	replace `v' = upper(`v')
}
duplicates drop
drop if pid==""

merge 1:m pid using AA_tax_roll_MLS_matches.dta, keep(matched) nogen
rename year listyear

foreach sch in elemschname jrhighname highschoolname {
	replace `sch' = "" if `sch'=="ANN_ARBOR"
}
replace elem_sch = upper(elemschname) if elem_sch=="" & elemschname~=""
replace mid_sch = upper(jrhighname) if mid_sch=="" & jrhighname~=""
replace high_sch = upper(highschoolname) if high_sch=="" & highschoolname~=""

replace elem_sch = "BURNS PARK" if elem_sch=="BURNS_PARK"
replace elem_sch = "BRYANT & PATTENGILL" if elem_sch=="BRYANT_PATTENGILL"
replace high_sch = "SKYLINE" if regexm(high_sch,"SKYLINE")

*CLEAN-UP DATA
drop if shortsaleyn=="Y"					/*Drop short sales.  Other related party transactions already ruled out by virtue of being listed.*/

*Convert prices in MLS data to dollars:
foreach p in listprice origlistprice soldprice previouslistprice concession assofeeperyear mls_sev mls_tv {
	replace `p' = `p'*1000
}


*CONSTRUCT REGRESSION VARIABLES:
*Tax benefits from inheritted capped TV are proportional to the number of days remaining until uncapping:
capture drop saledayofyear
gen saledayofyear = doy(solddate)
gen tenancydays = (365+1*(year(solddate)==2008))-saledayofyear+1
gen d = tenancydays/(365+1*(year(solddate)==2008))								/*Fraction of year remaining*/

*Use tax roll or prior MLS sale to identify last sale, whichever is more recent:
*saledate, L_saledate, lastsaleamt, and L_lastsaleamt are drawn from tax rolls.  solddate and soldprice are drawn from MLS.
replace saleyear = year(solddate)
sort pid solddate
gen L_solddate = saledate
replace L_solddate = max(solddate[_n-1],L_saledate) if pid==pid[_n-1] & solddate[_n-1]<solddate
replace L_solddate = L_saledate if year(L_solddate)==year(solddate)

gen L_soldprice = lastsaleamt if L_solddate==saledate
replace L_soldprice = soldprice[_n-1] if pid==pid[_n-1] & L_solddate==solddate[_n-1]
replace L_soldprice = L_lastsaleamt if L_solddate==L_saledate

gen l_saleyear = year(L_solddate)
gen yearsheld = saleyear - l_saleyear
tab yearsheld

format L_solddate %td
format L_saledate %td


*Covariates:
*Construct sale year, quarter, and month dummies to account for seasonal demand patterns and year FE
qui tab saleyear, gen(saleyear_dum)
gen salequarter = quarter(solddate)
replace salemonth = month(solddate)
qui tab salemonth, gen(month_dum)

replace yearbuilt = . if yearbuilt>saleyear
gen actualage = saleyear-yearbuilt
gen actualage2 = actualage^2

*Categorize 50 neighborhoods used by A2 Assessor.
qui tab neighborhood, gen(hood)

*Categorize elementary, middle, and high schools:
foreach level in elem mid high {
	tab `level'_sch, gen(`level'_sch)
}

foreach g in garage garage2 garage3 {
	replace `g' = "1" if `g'=="CAR"
	replace `g' = substr(`g',1,1) if regexm(`g',"C$")
	destring `g', force replace 
}
replace garage = garage2 if garage==. & garage2~=.
replace garage = garage3 if garage==. & garage3~=.

gen fire = (fireplace~="" | fireplace2~="" | fireplace3~="")
replace fire = 2 if fireplace=="TWO" | fireplace2=="TWO" | fireplace3=="TWO"
replace fire = 3 if fireplace=="THR" | fireplace2=="THR" | fireplace3=="THR"

gen I_pool = (pool=="IND" | pool=="ING" | pool2=="IND" | pool2=="ING")
gen I_air = (airconditioning=="CEN")
gen I_basement = (basement=="FUL" | basement=="FIN")

foreach v in sqft resfloorarea resgaragearea {
	replace `v' = `v'/1000
}


*ADD U.S. HPI AND CPI (AND IRM) DATA
gen l_salemonth = month(L_solddate)
save tax_cap_est_MLS_data.dta, replace

insheet using ../../USHPI.txt, clear tab names
foreach v of varlist _all {
	rename `v' l_`v'
}
merge 1:m l_saleyear l_salemonth using tax_cap_est_MLS_data.dta, keep(matched) nogen	/*Match historical HPI from prior post-Prop A sale*/
save tax_cap_est_MLS_data.dta, replace

insheet using ../../USHPI.txt, clear tab names
merge 1:m saleyear salemonth using tax_cap_est_MLS_data.dta, keep(matched) nogen		/*Match HPI from latest sale*/
save tax_cap_est_MLS_data.dta, replace

insheet using ../../USCPI.txt, clear tab names
foreach v of varlist _all {
	rename `v' l_`v'
}
merge 1:m l_saleyear using tax_cap_est_MLS_data.dta, keep(matched) nogen				/*Match historical CPI from prior post-Prop A sale*/
save tax_cap_est_MLS_data.dta, replace

insheet using ../../USCPI.txt, clear tab names
merge 1:m saleyear using tax_cap_est_MLS_data.dta, keep(matched) nogen					/*Match CPI from latest sale*/
save tax_cap_est_MLS_data.dta, replace


*Append average assessment growth
use "`path'/Ann_Arbor/AA_proptaxdata19972008/Values_19972008.dta", clear
merge 1:1 pid year using ../AA_tax_roll.dta, nogen
keep if class==401 | class==.
keep pid year sev tv

*Compute annual average SEV growth and construct corresponding assessment index:
sort pid year
by pid: gen sev_pct = sev/sev[_n-1]
bysort year: egen avg_sev_pct = mean(sev_pct)
*table year, c(p50 avg_sev_pct)
gen ai = 100 if year==1997
sort pid year
by pid: replace ai = ai[_n-1]*avg_sev_pct if year>1997 & year==year[_n-1]+1 & ai[_n-1]~=.
bysort year: egen max_ai = max(ai)
replace ai = max_ai
sort pid year
*table year, c(max ai p50 ai min ai)
drop *pct max_ai

save "`path'/Ann_Arbor/AA_proptaxdata19972008/Values_19972010.dta", replace
rename sev sev_hist
rename tv tv_hist
rename year l_saleyear
rename ai l_ai
merge 1:m pid l_saleyear using tax_cap_est_MLS_data.dta, keep(matched) nogen		/*Match SEV, TV, and "assessment index" from prior post-1997 sale*/
save tax_cap_est_MLS_data.dta, replace

use "`path'/Ann_Arbor/AA_proptaxdata19972008/Values_19972010.dta", clear
rename year saleyear
merge 1:m pid saleyear using tax_cap_est_MLS_data.dta/*, keep(matched master)*/			/*Match SEV, TV, and "assessment index" from latest sale*/
gen year = saleyear
replace saleyear = . if _merge==1

*Re-compute age of renovations:
sort pid year
local y = "1998"
replace irm = 2.7 if year==`y'
foreach i in 1.6 1.9 3.2 3.2 1.5 2.3 2.3 3.3 3.7 2.3 4.4 -0.3 {
	local y = `y'+1
	replace irm = `i' if year==`y'
}

capture drop tv_pct 
capture drop *renov*
by pid: gen tv_pct = ((tv/tv[_n-1])-1)*100 if year==year[_n-1]+1
replace tv_pct = round(tv_pct,0.1)

by pid: gen renov = saleyear[_n-1] if saleyear==. & saleyear[_n-1]~=.
replace renov = l_saleyear if saleyear~=.
by pid: replace renov = year if irm[_n+1]<tv_pct[_n+1] & tv_pct[_n+1]~=. & saleyear==. & year==year[_n+1]-1
by pid: replace renov = renov[_n-1] if (renov[_n-1]>renov | renov==.) & renov[_n-1]~=. 

gen renovage = saleyear-renov if saleyear~=.

drop if _merge~=3
drop *pct *renov _merge year

*tab renovage saleyear
*tab yearsheld saleyear
*gen tmp = yearsheld - renovage
*summ tmp, detail

save tax_cap_est_MLS_data.dta, replace
/**/


use tax_cap_est_MLS_data.dta, clear
*------------------------------------------------------------------------------------------------------------------------------------------------------
*Compute tax benefit associated with inheriting capped TV for the year in which sale occurs
local av = "mls_sev"
local indep = "tvcapval"

local se = "vce(cluster neighborhood)"

gen tvcapval = (`av'-mls_tv)*mills/1000*d	/*Pro-rated*/
gen d_tax = (`av'-mls_tv)*mills/1000		/*Full-year capped TV tax benefit*/
*------------------------------------------------------------------------------------------------------------------------------------------------------

drop if tvcapval<0								

*ADD RHS CONTROL FOR FUTURE TAX LIABILITY (AS IN CAPITALIZATION MODEL)
*Compute period 0 full-year tax liability
gen tax_0 = mls_tv*mills/1000
*Compute period n>0 full-year tax liability
gen tax_n = F_sev*mills/1000
gen prox_tax_n = `av'*mills/1000

*INCLUDE RHS MEASURE OF "PREDICTED" SALE PRICE USING LAST SALE PRICE INFLATED BY HPI GROWTH
gen E_saleamt_enc = L_soldprice*(enc_hpi/l_enc_hpi)	/*East North Central Census Division*/

*CONSTRUCT CANDIDATE INSTRUMENTS:
sort pid solddate soldprice
gen E_sev_ai = sev_hist*(ai/l_ai)*mills/1000				/*Ann Arbor average assessed value growth*/
gen E_sev_irmi = sev_hist*(irmi/l_irmi)*mills/1000
gen E_d_tax = E_sev_ai - E_sev_irmi

*TAKE LOGS OF DOLLAR-DENOMINATED FIGURES
foreach v in soldprice tvcapval d_tax d E_saleamt_enc E_d_tax tax_n prox_tax_n E_sev_ai {
	gen log_`v' = log(`v')
}
*Artificially preserve data with 0 capped TV benefits:
*Doing so modifies the interpretation of the estimated partial effects (i.e. object of interest is d(ln(y))/d(ln(x)), not d(ln(y+1))/d(ln(x)))
*and requires a recomputation of the latter to recover the former.
*replace log_tvcapval = log(tvcapval+1) if tvcapval~=.
*local subf = "/Log0"
local subf = ""

*Flag new construction
gen I_new = (resyearbuilt==saleyear | resyearbuilt==saleyear-1 | yearbuilt==saleyear | yearbuilt==saleyear-1)
*tab saleyear I_new		
*drop if I_new
	
*DEFINE VECTORS OF COVARIATES
local area_X = "hood1-hood47"																		/*Omits Neighborhood 52*/
local school_X = "elem_sch1-elem_sch17 mid_sch1 mid_sch2 mid_sch4 mid_sch5 high_sch1 high_sch2"		/*Omits Wines, Scarlett, and Skyline*/
local month_X = "month_dum1-month_dum11"
local year_X = "saleyear_dum1-saleyear_dum5"

local house_MLS_X "sqft garage fire i.I_basement i.I_air i.I_pool bd fhb actualage actualage2 renovage"
local house_MLS_X_nofv "sqft garage fire I_basement I_air I_pool bd fhb actualage actualage2 renovage"

local house_X "`house_MLS_X_nofv'"

local soph_X "i.I_Reinhart c.avg_brokershare"
local soph_X_nofv "I_Reinhart avg_brokershare"

gen I_experience = (I_moved==1 | I_invested==1)
local buyer_soph_X "i.I_experience"
local buyer_soph_X_nofv "I_experience"

*Define neighborhood-year FE:
quietly {
 foreach h of varlist `area_X' {
	foreach y of varlist `year_X' {
		local yy = "year_"+substr("`y'",13,length("`y'")-13+1)
		gen `h'_x_`yy' = `h'*`y'
	}
 }
}
local area_x_year = "hood*_x_year*"
local area_X = "`area_X' `area_x_year'"

*------------------------------------------------------------------------------------------------------------------------------------------------------
local ivcmd = "ivreg2"
local ivopt = "cluster(neighborhood) first partial(`area_X' `school_X' `year_X' `month_X')"
*------------------------------------------------------------------------------------------------------------------------------------------------------

disp "REGRESSIONS BY `indep'"
disp "Assessed value = `av'"

*ESTIMATE CAPITALIZATION OF CAPPED TV BENEFITS FOLLOWING METHODOLOGY IN tax_cap_est_ivreg2.do
#delimit ;
qui reg soldprice `indep' prox_tax_n E_saleamt_enc `house_X' `area_X' `school_X' `year_X' `month_X' if yearsheld~=. & E_sev_ai~=.;
summ soldprice if e(sample), detail;
qui reg log_soldprice log_`indep' log_prox_tax_n log_E_saleamt_enc `house_X' `area_X' `school_X' `year_X' `month_X' if yearsheld~=. & log_E_sev_ai~=.;
summ soldprice if e(sample), detail;

drop if soldprice<=1000 | soldprice>=875000;		/*Exclude top and bottom 1 percent of transaction prices in estimation sample from first IV*/
drop if tvcapval>4000 | (tvcapval<1 & tvcapval>0);	/*Exclude top ~1+ percent of capped TV benefits*/ 
*drop if tvcapval<1 & tvcapval>0;					/*Exclude handful of observations with trivially small capped TV benefits due in most cases to small d*/
drop if tvcapval<5 & tvcapval>0;					/*Exclude bottom ~1+ percent of non-zero capped TV benefits*/ 

drop if soldprice<10000 | soldprice>500000;
local subf = "/10-500kCens";


/**/
*LOGS;
*OLS;
reg log_soldprice log_`indep' log_E_saleamt_enc  `house_X' `area_X' `school_X' `year_X' `month_X' if yearsheld~=., `se';
estimates store ols_logs_spec1;

*USED TO PRODUCE SPECIFICATION (1) RESULTS SHOWN IN TABLE 6;
reg log_soldprice log_`indep' log_prox_tax_n log_E_saleamt_enc  `house_X' `area_X' `school_X' `year_X' `month_X' 
	if yearsheld~=. & log_E_sev_ai~=., `se';
estimates store ols_logs_spec2;


*IV;
`ivcmd' log_soldprice log_E_saleamt_enc `house_X' `area_X' `school_X' `year_X' `month_X' (log_`indep' = yearsheld), `ivopt'
	endog(log_`indep') savefirst savefprefix("iv1_s1_") rf;
estimates store iv1_logs_stage2;
summarize tvcapval if e(sample), detail;
summarize d_tax if e(sample), detail;
summarize soldprice if e(sample), detail;

`ivcmd' log_soldprice log_E_saleamt_enc `house_X' `area_X' `school_X' `year_X' `month_X' (log_`indep' = log_E_d_tax), `ivopt'
	endog(log_`indep') savefirst savefprefix("iv1_s1_alt_") rf;
estimates store iv1_logs_stage2_alt;

*USED TO PRODUCE SPECIFICATION (2) RESULTS SHOWN IN TABLE 6;
`ivcmd' log_soldprice log_E_saleamt_enc `house_X' `area_X' `school_X' `year_X' `month_X' (log_`indep' log_prox_tax_n = yearsheld log_E_sev_ai), `ivopt'
	/*endog(log_`indep' log_prox_tax_n)*/ savefirst savefprefix("iv2_s1_") rf;
estimates store iv2_logs_stage2;
summarize tvcapval if e(sample), detail;
summarize d_tax if e(sample), detail;
summarize soldprice if e(sample), detail;

`ivcmd' log_soldprice log_E_saleamt_enc `house_X' `area_X' `school_X' `year_X' `month_X' (log_`indep' log_prox_tax_n = log_E_d_tax E_sev_ai), `ivopt'
	/*endog(log_`indep' log_prox_tax_n)*/ savefirst savefprefix("iv2_s1_alt_") rf;
estimates store iv2_logs_stage2_alt;
/**/
	
	
*RE-ESTIMATE CAPITALIZATION WITH INDICATOR FOR REINHART-LISTED PROPERTIES AND/OR LISTING BROKER EXPERIENCE (MARKET SHARE);
*LOGS;
*OLS;
reg log_soldprice c.log_`indep'##(`soph_X') log_E_saleamt_enc  `house_X' `area_X' `school_X' `year_X' `month_X' if yearsheld~=., `se';
estimates store ols_logs_soph_spec1;
foreach c in `soph_X_nofv' {;
	tab `c' if e(sample);
};
reg log_soldprice log_`indep' log_E_saleamt_enc  `house_X' `area_X' `school_X' `year_X' `month_X' if e(sample), `se';

reg log_soldprice c.log_`indep'##(`soph_X') log_prox_tax_n log_E_saleamt_enc  `house_X' `area_X' `school_X' `year_X' `month_X' 
	if yearsheld~=. & log_E_sev_ai~=., `se';
estimates store ols_logs_soph_spec2;
foreach c in `soph_X_nofv' {;
	tab `c' if e(sample);
};
reg log_soldprice log_`indep' log_prox_tax_n log_E_saleamt_enc  `house_X' `area_X' `school_X' `year_X' `month_X' if e(sample), `se';


*IV;
local endo_int "";
local exo_int "";
local soph_exo "";
local cc = 1;
foreach c in `soph_X_nofv' {;
	replace endo_x_`c' = log_`indep'*`c';
	local endo_int "`endo_int' endo_x_`c'";
	local exo_int "`exo_int' yearsheld_x_`c'";
	*local soph_exo "`soph_exo' `c'";
	local soph_exo "`soph_X_nofv'";
	
	`ivcmd' log_soldprice `soph_exo' log_E_saleamt_enc `house_X' `area_X' `school_X' `year_X' `month_X' (log_`indep' endo_x_`c' = yearsheld yearsheld_x_`c'), `ivopt'
		savefirst savefprefix("iv1_soph`cc'_s1_") rf;
	estimates store iv1_logs_soph`cc'_stage2;

	*USED TO PRODUCE SPECIFICATION (3) RESULTS SHOWN IN TABLE 6;
	`ivcmd' log_soldprice `soph_exo' log_E_saleamt_enc `house_X' `area_X' `school_X' `year_X' `month_X' 
		(log_`indep' endo_x_`c' log_prox_tax_n = yearsheld yearsheld_x_`c' log_E_sev_ai), `ivopt' savefirst savefprefix("iv2_soph`cc'_s1_") rf;
	estimates store iv2_logs_soph`cc'_stage2;	
	test log_`indep' + endo_x_`c' = 0;
	disp "95% C.I.: [",(_b[log_tvcapval]+_b[endo_x_`c'])-1.96*abs((_b[log_tvcapval]+_b[endo_x_`c'])/sqrt(r(chi2))),",",(_b[log_tvcapval]+_b[endo_x_`c'])+1.96*abs((_b[log_tvcapval]+_b[endo_x_`c'])/sqrt(r(chi2))),"]";
	
	if `cc'>1 {;
	  local cc = `cc'+1;
	  `ivcmd' log_soldprice `soph_exo' log_E_saleamt_enc `house_X' `area_X' `school_X' `year_X' `month_X' (log_`indep' `endo_int' = yearsheld `exo_int'), `ivopt'
		savefirst savefprefix("iv1_soph`cc'_s1_") rf;
	  estimates store iv1_logs_soph`cc'_stage2;

	  `ivcmd' log_soldprice `soph_exo' log_E_saleamt_enc `house_X' `area_X' `school_X' `year_X' `month_X' 
		(log_`indep' `endo_int' log_prox_tax_n = yearsheld `exo_int' log_E_sev_ai), `ivopt'	savefirst savefprefix("iv2_soph`cc'_s1_") rf;
	  estimates store iv2_logs_soph`cc'_stage2;
	};
	else {;
	  local cc = `cc'+1;
	};
};


*RE-ESTIMATE CAPITALIZATION WITH INDICATORS FOR EXPERIENCED HOMEBUYERS/INVESTORS;
*LOGS;
*OLS;
reg log_soldprice c.log_`indep'##(`buyer_soph_X') log_E_saleamt_enc  `house_X' `area_X' `school_X' `year_X' `month_X' if yearsheld~=., `se';
estimates store ols_logs_bsoph_spec1;
foreach c in `buyer_soph_X_nofv' {;
	tab `c' if e(sample);
};
reg log_soldprice log_`indep' log_E_saleamt_enc  `house_X' `area_X' `school_X' `year_X' `month_X' if e(sample), `se';

reg log_soldprice c.log_`indep'##(`buyer_soph_X') log_prox_tax_n log_E_saleamt_enc  `house_X' `area_X' `school_X' `year_X' `month_X' 
	if yearsheld~=. & log_E_sev_ai~=., `se';
estimates store ols_logs_bsoph_spec2;
foreach c in `buyer_soph_X_nofv' {;
	tab `c' if e(sample);
};
reg log_soldprice log_`indep' log_prox_tax_n log_E_saleamt_enc  `house_X' `area_X' `school_X' `year_X' `month_X' if e(sample), `se';

*IV;
local endo_int "";
local exo_int "";
local soph_exo "";
local cc = 1;
foreach c in `buyer_soph_X_nofv' {;
	replace endo_x_`c' = log_`indep'*`c';
	local endo_int "`endo_int' endo_x_`c'";
	local exo_int "`exo_int' yearsheld_x_`c'";
	*local soph_exo "`soph_exo' `c'";
	local soph_exo "`buyer_soph_X_nofv'";

	`ivcmd' log_soldprice `soph_exo' log_E_saleamt_enc `house_X' `area_X' `school_X' `year_X' `month_X' (log_`indep' endo_x_`c' = yearsheld yearsheld_x_`c'), `ivopt'
		savefirst savefprefix("iv1_bsoph`cc'_s1_") rf;
	estimates store iv1_logs_bsoph`cc'_stage2;

	*USED TO PRODUCE SPECIFICATION (4) RESULTS SHOWN IN TABLE 6;
	`ivcmd' log_soldprice `soph_exo' log_E_saleamt_enc `house_X' `area_X' `school_X' `year_X' `month_X' 
		(log_`indep' endo_x_`c' log_prox_tax_n = yearsheld yearsheld_x_`c' log_E_sev_ai), `ivopt' savefirst savefprefix("iv2_bsoph`cc'_s1_") rf;
	estimates store iv2_logs_bsoph`cc'_stage2;	
	
	if `cc'>1 {;
	  local cc = `cc'+1;
	  `ivcmd' log_soldprice `soph_exo' log_E_saleamt_enc `house_X' `area_X' `school_X' `year_X' `month_X' (log_`indep' `endo_int' = yearsheld `exo_int'), `ivopt'
		savefirst savefprefix("iv1_bsoph`cc'_s1_") rf;
	  estimates store iv1_logs_bsoph`cc'_stage2;

	  `ivcmd' log_soldprice `soph_exo' log_E_saleamt_enc `house_X' `area_X' `school_X' `year_X' `month_X' 
		(log_`indep' `endo_int' log_prox_tax_n = yearsheld `exo_int' log_E_sev_ai), `ivopt'	savefirst savefprefix("iv2_bsoph`cc'_s1_") rf;
	  estimates store iv2_logs_bsoph`cc'_stage2;
	};
	else {;
	  local cc = `cc'+1;
	};
};

	
*Output Key Results;
capture mkdir "`path'/Ann_Arbor/MLS/TEX_Tables/Prop_Tax_Cap`subf'";
local outpath "`path'/Ann_Arbor/MLS/TEX_Tables/Prop_Tax_Cap`subf'";
local outtype "tex";
outreg2 log_`indep' log_prox_tax_n log_E_saleamt_enc `house_X' [ols_logs_spec1 ols_logs_spec2] using "`outpath'/ols_logs_`indep'", replace `outtype' 
	stats(coef se) paren(se) symbol(***,**,*) /*side*/ dec(3) adjr2	nocons title("OLS Capitalization Results");
outreg2 log_`indep' log_prox_tax_n `house_X' [iv1_logs_stage2 iv2_logs_stage2] using "`outpath'/iv_logs_stage2_`indep'", replace `outtype' stats(coef se) paren(se) 
	symbol(***,**,*) /*side*/ dec(3) adjr2 nocons title("IV Capitalization Results");
/*outreg2 [iv1_s1_log_tvcapval iv2_s1_log_tvcapval iv2_s1_log_prox_tax_n] using "`outpath'/iv_logs_stage1_`indep'", 
	replace `outtype' stats(coef se) paren(se) symbol(***,**,*) /*side*/ dec(3) adjr2 nocons title("First-Stage IV Capitalization Results")
	sortvar(yearsheld log_E_sev_ai `house_X') drop(*dum* *_sch* hood*) addstat(Kleibergen-Paap rk Wald F statistic, e(widstat));*/
outreg2 log_`indep' log_prox_tax_n `house_X' [iv1_logs_stage2_alt iv2_logs_stage2_alt] using "`outpath'/iv_logs_stage2_alt_`indep'", replace `outtype' stats(coef se) paren(se) 
	symbol(***,**,*) /*side*/ dec(3) adjr2 nocons title("IV Capitalization Results");

outreg2 [ols_logs_soph_spec1 ols_logs_soph_spec2] using "`outpath'/ols_logs_soph_`indep'", replace `outtype' stats(coef se) paren(se) symbol(***,**,*) drop(*dum* *_sch* hood*)
	/*side*/ sortvar(log_`indep' log_prox_tax_n) dec(3) adjr2 nocons title("OLS Capitalization Results");
outreg2 [iv1_logs_soph1_stage2 iv1_logs_soph2_stage2 iv1_logs_soph3_stage2 iv2_logs_soph1_stage2 iv2_logs_soph2_stage2 iv2_logs_soph3_stage2] using "`outpath'/iv_logs_soph_stage2_`indep'", 
	replace `outtype' stats(coef se) paren(se) symbol(***,**,*) drop(*dum* *_sch* hood*) /*side*/ sortvar(log_`indep' log_prox_tax_n) dec(3) adjr2 nocons title("IV Capitalization Results");
outreg2 [ols_logs_bsoph_spec1 ols_logs_bsoph_spec2] using "`outpath'/ols_logs_bsoph_`indep'", replace `outtype' stats(coef se) paren(se) symbol(***,**,*) drop(*dum* *_sch* hood*)
	/*side*/ sortvar(log_`indep' log_prox_tax_n) dec(3) adjr2 nocons title("OLS Capitalization Results");
outreg2 [iv1_logs_bsoph1_stage2 iv2_logs_bsoph1_stage2] using "`outpath'/iv_logs_bsoph_stage2_`indep'", 
	replace `outtype' stats(coef se) paren(se) symbol(***,**,*) drop(*dum* *_sch* hood*) /*side*/ sortvar(log_`indep' log_prox_tax_n) dec(3) adjr2 nocons title("IV Capitalization Results");		

	
foreach e in iv2_s1_log_`indep' iv2_s1_log_prox_tax_n {;
	if "`e'"=="iv2_s1_log_`indep'" {;
		local outopt = "replace";
	};
	else {;
		local outopt = "";
	};
	estimates restore `e';
	outreg2 using "`outpath'/iv2_logs_stage1_`indep'", `outopt' `outtype' stats(coef se) paren(se) symbol(***,**,*) /*side*/ dec(3) adjr2 nocons title("First-Stage IV Capitalization Results")
	  sortvar(yearsheld log_E_sev_ai `house_X') drop(*dum* *_sch* hood*) addstat(Kleibergen-Paap rk Wald F statistic, e(widstat));
};

*OUTPUT TABLE 6;
outreg2 [ols_logs_spec2 iv2_logs_stage2 iv2_logs_soph1_stage2 iv2_logs_bsoph1_stage2] using "`outpath'/ols_iv_tables_`indep'", 
	replace `outtype' stats(coef se) paren(se) symbol(***,**,*) drop(*dum* *_sch* hood*) /*side*/ sortvar(log_`indep' log_prox_tax_n) dec(3) adjr2 nocons title("MLS Capitalization Results");	

#delimit cr
log close


/**/
